﻿using System;
using System.Configuration;

namespace ApiScanner.Core
{
    public sealed class ScannerConfigurationSection: ConfigurationSection
    {
        private const string SectionName = "scannerConfiguration";

        public static ScannerConfigurationSection Open(Configuration configuration)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");

            return (ScannerConfigurationSection) configuration.GetSection(SectionName);
        }

        [ConfigurationProperty("tests")]
        public TestConfigurationElementCollection Tests
        {
            get { return (TestConfigurationElementCollection) this["tests"]; }
            set { this["tests"] = value; }
        }

        public static ScannerConfigurationSection Create(Configuration configurationManager)
        {
            if (configurationManager == null) throw new ArgumentNullException("configurationManager");
            var result = new ScannerConfigurationSection();
            configurationManager.Sections.Add(SectionName, result);
            return result;
        }

        public void RegisterOnConfiguration(Configuration configurationManager)
        {
            if (configurationManager == null) throw new ArgumentNullException("configurationManager");
            configurationManager.Sections.Add(SectionName, this);
        }
    }
}